package console

import (
	"strings"
)

type helpCommand struct{}

func (command *helpCommand) Name() string {
	return "help"
}

func (command *helpCommand) Help() string {
	return "this help text"
}

func (command *helpCommand) Run([]string) string {
	endLine := "\r\n"
	builder := new(strings.Builder)
	builder.WriteString("commands:")
	builder.WriteString(endLine)

	for _, command := range sorted {
		name := command.Name()
		builder.WriteString(name)
		nameLength := len(name)
		if nameLength < maxNameLength {
			for i := nameLength; i < maxNameLength; i++ {
				builder.WriteRune(' ')
			}
		}

		builder.WriteString(" - ")
		builder.WriteString(command.Help())
		builder.WriteString(endLine)
	}

	return builder.String()
}
